<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
            float: left;
        }
    </style>
</head>
<body>
<div>
    <img src="image/a.png">
</div>
<div style="position: relative">
    <img src="image/b.png" id="b">
</div>


<script>

    function getAbsOffset(obj){
        function getOffsetAX(obj){
            var x = 0;
            if (obj.offsetParent){
                return x + obj.offsetLeft+getOffsetAX(obj.offsetParent);
            } else {
                return 0;
            }
        }
        function getOffsetAY(obj){
            var x = 0;
            if (obj.offsetParent){
                return x + obj.offsetTop+getOffsetAY(obj.offsetParent);
            } else {
                return 0;
            }
        }
        return {
            left:getOffsetAX(obj),
            top:getOffsetAY(obj)
        }
    }

    function getMousePositionOnObj(obj,e){
        var absPostion = getAbsOffset(obj);
        return {
            x:e.clientX-absPostion.left,
            y:e.clientY-absPostion.top
        }
    }
    //
    var b = document.getElementById('b');


    b.onclick = function(e){
        var okPoints = [
            [118,8,30,30]
        ];
        var mousePosition = getMousePositionOnObj(this,e);  //
        if (mousePosition.x>118 && mousePosition.y>8 && mousePosition.x<118+30 && mousePosition.y < 8+30){
            var img = document.createElement('img');
            img.src = 'image/right.png';
            img.style.position = 'absolute';
            img.style.left = '118px';
            img.style.top = '8px';
            img.style.width = '20px';
            this.parentNode.appendChild(img);

        } else {
            var img = document.createElement('img');
            img.src = 'image/wrong.png';
            img.style.position = 'absolute';
            img.style.left = mousePosition.x+'px';
            img.style.top = mousePosition.y+'px';
            img.style.width = '20px';
            this.parentNode.appendChild(img);
        }

    }
</script>
</body>
</html>